﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UVTileSpeed : MonoBehaviour 
{
    Material m;
    Vector2 _speed = new Vector2(0.5f,0.0f);
	// Use this for initialization
	void Start ()
    {
        m = GetComponent<MeshRenderer>().material;	
	}
	
    public void SetSpeed(Vector2 speed)
    {
        if(speed.magnitude > 0.01f)
        {
            _speed = speed;
        }
        else
        {
            _speed = Vector2.zero;
        }
    }

    void OnBecameVisible()
    {
        enabled = true;
    }


    void OnBecameInvisible()
    {
        enabled = false;
    }


    // Update is called once per frame
    void Update () 
    {
        m.mainTextureOffset += _speed * Time.deltaTime;	    	
	}
}
